from api.views import *
from api.models.Choices import choices_collects
from enum import EnumMeta
from core.config import cfg
class publish_choices(APIView):
    # notes
    def get(self, request, format=None):
        '''
        '''
        result = {}
        for v in choices_collects.__dict__.items():
            if isinstance(v, tuple):
                if v.__len__() == 2:
                    if isinstance(v[1], EnumMeta):
                        result[v[0]]= {}
                        result[v[0]]["service"]= cfg.SERVICE_KEY
                        result[v[0]]["types"]= ""
                        result[v[0]]["construct"]={}
                        for v_k, v_v in v[1].__members__.items():
                            if not result[v[0]]["types"]:
                                result[v[0]]["types"]= "IntegerChoices" if isinstance(v_v,int) else "TextChoices"
                            result[v[0]]["construct"][v_k]={
                                    'name': v_v.name,
                                    'label': v_v.label,
                                    'value': v_v.value
                                }
        return Response(stateCode=200,data=result)